<?php
namespace app\pay\controller\fumin;

use pay\fumin\RequestHandler;
use pay\fumin\Config;
/*
 * 订单查询
 */
class Orderquery extends Base {   
    /*
     * 经畅远中转查询接口
     */
    public function index() {
        
        $data = input('post.');
        
        $verSign = $data['signature'];
        unset($data['signature']); 
        $data['signature'] = $this->changyuanSign($data); // 创建签名
        $data['service'] = 'service.trans.query';
        
        // 验证签名
        if($verSign == $data['signature']) {
            
            if($data['mchntOrderNo'] != null) {
                $ret = model('PayBisOrder')->get(['mchnt_order_no' => $data['mchntOrderNo']]);
            }
            if($data['orderNo'] != null) {
                $ret = model('PayBisOrder')->get(['pay_orderid' => $data['orderNo']]);
            }
            
            if($ret) {
                $Config = new Config();
                $ReqHandler = new RequestHandler();
                // 重新组装发送到富民的数据
                $dataToFumin = $this->reqFuminData($data, $Config->C('orderQueryUrl'));
                $dataToFuminArr = json_decode($dataToFumin, true);
                unset($dataToFuminArr['fee']); 
                unset($dataToFuminArr['signature']); 
                $dataToFuminArr['fee'] = model('PayBisOrder')->get(['pay_orderid' => $dataToFuminArr['orderNo']])->fee;
                $dataToFuminArr['signature'] = $ReqHandler->createSign($dataToFuminArr); // 创建签名
                return json_encode($dataToFuminArr, 320);
            }
        } else {
            $resArr = array(
                'msg'  => '签名验证失败',
                'code' => '401'
            );
            return json_encode($resArr, 320);
        }
    }
 
}

